using System.Collections.Generic;
using abilities.effects;
using LitJson;

namespace abilities.templates
{
    public class EffectLimitsTemplate : EffectTemplate
    {
        Dictionary<int, List<int>> ranges;

        public EffectLimitsTemplate() : base()
        {
        }

        public override Effect CreateInstance(int level)
        {
            return new EffectLimits(this,level);;
        }

        public override bool FromJson(JsonData value)
        {
            if (!base.FromJson(value))
                return false;
            if (value["ranges"].GetJsonType() == JsonType.Array)
                return false;
            ranges = new();
            foreach (JsonData i in value["ranges"])
            {
                List<int> damage = new();
                FromJsonToArray(i["damage"], damage);
                ranges.Add( (int)i["health"], damage);
            }

            return true;
        }

        public Dictionary<int, int> GetRanges(int level)
        {
            Dictionary<int, int> result = new();
            foreach (var it in ranges)
            {
                result.Add(it.Key, GetByLevel(it.Value, level));
            }

            return result;
        }
    }
}